package cn.icanci.loopstack.pcc.test.meta;

import java.util.function.Function;

import cn.icanci.loopstack.pcc.model.MetaCell;
import cn.icanci.loopstack.pcc.test.key.KeyEnum;
import cn.icanci.loopstack.pcc.test.order.Order;
import cn.icanci.loopstack.pcc.test.req.GoodsReq;
import cn.icanci.loopstack.pcc.test.resp.GoodsResp;

/**
 * @author icanci
 * @since 1.0 Created in 2024/08/02 15:22
 */
public class GoodsMetaCell extends MetaCell<GoodsReq, GoodsResp, Order> {

    public GoodsMetaCell(GoodsReq goodsReq, Function<GoodsReq, GoodsResp> function) {
        super(goodsReq, function);
    }

    /**
     * 返回元组唯一Key，其在每个组中是唯一的
     *
     * @return 元组唯一Key
     */
    @Override
    public String uniqueKey() {
        return KeyEnum.GOODS.name();
    }

    @Override
    public Order adapter(GoodsResp goodsResp) {
        Order order = new Order();
        order.setTraceId(goodsResp.getTraceId());
        order.setOrderSerialNo(goodsResp.getOrderSerialNo());
        order.setPrice(goodsResp.getGoodsPrice());
        return order;
    }
}
